﻿using PostSharp.Aspects;
using PostSharp.Serialization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataChangeTools.Utils.Attribute
{

    [PSerializable]
    [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]

    public class LogAttribute : OnMethodBoundaryAspect
    {
        public LoggingHelper Helper;
        public string ActionName { get; set; }
        public override void OnEntry(MethodExecutionArgs eventArgs)
        {
            Helper = new LoggingHelper();
            Helper.Writelog(ActionName + "开始执行");
        }

        public override void OnExit(MethodExecutionArgs eventArgs)
        {
            Helper = new LoggingHelper();
            string name = eventArgs.Method.Name;//用这种方式也能获取特性修饰的函数的名称
            string value = eventArgs.ReturnValue.ToString();

            Helper.Writelog(name + "的返回值：" + value);
        }


    }
}
